//
//  FKSetPayPwdVC.m
//  inspectVehicle
//
//  Created by Macbook Pro on 2018/12/12.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKSetPayPwdVC.h"

@interface FKSetPayPwdVC ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UITextField *confirmPwdField;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;

@end

@implementation FKSetPayPwdVC

- (instancetype)init
{
    return [UIStoryboard storyboardWithName:@"FKSetPayPwdVC" bundle:nil].instantiateInitialViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (![string isEqualToString:@""]) {
        if (![string fk_isPureInt]) {
            return false;
        }
        if (textField.text.length >= 6 ) {
            return false;
        }
    }
    return true;
}

- (IBAction)confirmBtnClicked:(UIButton *)sender {
    [self.view endEditing:true];
    
    if (self.pwdField.text.length != 6) {
        [SVProgressHUD showInfoWithStatus:@"请输入6位数的支付密码"];
        return;
    }
    if (self.confirmPwdField.text.length != 6) {
        [SVProgressHUD showInfoWithStatus:@"请输入6位数的确认密码"];
        return;
    }
    if (![self.pwdField.text isEqualToString:self.confirmPwdField.text]) {
        [SVProgressHUD showInfoWithStatus:@"两次输入的密码不一致!"];
        return;
    }
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"pwd"] = self.pwdField.text;
    param[@"confirm_password"] = self.confirmPwdField.text;
    [SVProgressHUD show];
    [FKHttpTool postWithSuffix:@"m=Home&c=Mine&a=set_pay" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            [FKCacheTool savePayPwd:@"1"];
            [SVProgressHUD dismiss];
            [SVProgressHUD showSuccessWithStatus:@"支付密码设置成功!"];
            fkPopVC;
        }
    } failure:nil];
}

@end
